﻿@model IEnumerable<WineStore.Models.Category>
@{
    ViewBag.Title = "ShowCategory";
    Layout = "~/Views/Shared/AdminLayout.cshtml";
}
@section Styles
{
}
@section Scripts
{
    <script src="../../Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            $(".RemoveCategory").click(function () {
                if (confirm("Are you sure delete "+$(this).attr("data-name")+" ?")) {
                    // Get the id from the link 
                    var recordToDelete = $(this).attr("data-id");
                    if (recordToDelete != '') {
                        clearUpdateMessage();
                        // Perform the ajax post 
                        $.post("/Category/DeleteCategory", { "id": recordToDelete },
            function (data) {
                // Successful requests get here 
                // Update the page elements 
                $('#row-' + data.Id).fadeOut('slow');
                $('#update-message').text(htmlDecode(data.Message));

            });
                    }
                }
            });
        });

        // Goi thong bao
        function clearUpdateMessage() {
            //Reset update-message area
            $('#update-message').text('');
        }

        // Giai ma thong bao
        function htmlDecode(value) {
            if (value) {
                return $('<div />').html(value).text();
            }
            else {
                return '';
            }
        }
    </script>
}
<!-- Table (TABLE) -->
@using (Html.BeginForm())
{
    <h3 class="tit">
        Category List
    </h3>
    <div style="color: Red; font-size: 13px;" id="update-message">
    </div>
    <table border="1px;">
        <tr>
            <th>
                Category Id
            </th>
            <th>
                Category Name
            </th>
            <th>
                Change
            </th>
        </tr>
        @foreach (var item in Model)
        {
            <tr id="row-@item.CategoryId">
                <td>
                    @Html.DisplayFor(product => item.CategoryId)
                </td>
                <td>
                    @Html.DisplayFor(product => item.CategoryName)
                </td>
                <td>
                    @Html.ActionLink("Edit", "EditCategory", new { id = item.CategoryId })
                    <a href="#" class="RemoveCategory" data-id="@item.CategoryId" data-name="@item.CategoryName">Delete</a>
                </td>
            </tr>
        }
        <tr>
            <td colspan="3" align="right">
                @Html.ActionLink("Create Category", "CreateCategory")
            </td>
        </tr>
    </table>
}